<?php

namespace app\api\controller;

use app\services\PrizeDrawService;
use plugin\admin\app\model\PrizeDrawActivity;
use support\Request;

class PrizeDrawController
{
    public function list(Request $request)
    {
        try {
            $page = $request->post('page', 1);
            $length = $request->post('length', 10);
            $type = $request->post('type', PrizeDrawActivity::TYPE_SINGLE);

            $data = PrizeDrawService::list($page, $length, $type);

            return ok_rsp('成功', $data);
        } catch (\Exception $e) {
            echo $e->getMessage() . $e->getTraceAsString();
            return err_rsp($e->getMessage());
        }
    }

    public function detail(Request $request)
    {
        try {
            $id = $request->post('id');

            $data = PrizeDrawService::detail($id);

            return ok_rsp('成功', $data);
        } catch (\Exception $e) {
            echo $e->getMessage() . $e->getTraceAsString();
            return err_rsp($e->getMessage());
        }
    }
}